package com.wayne.testapp.activity;

import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.view.View;

import com.wayne.testapp.R;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.RequestMethod;
import com.yolanda.nohttp.rest.CacheMode;
import com.yolanda.nohttp.rest.OnResponseListener;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.RequestQueue;
import com.yolanda.nohttp.rest.Response;

import org.json.JSONObject;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by wayne on 2016/06/29.
 */
public class TestNoHttpActivity extends BaseActivity {
    @InjectView(R.id.bt_request1)
    AppCompatButton btRequest1;
    @InjectView(R.id.bt_request2)
    AppCompatButton btRequest2;
    @InjectView(R.id.bt_request3)
    AppCompatButton btRequest3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_test_nohttp);
        ButterKnife.inject(this);
    }
    long time;
    @OnClick({R.id.bt_request1, R.id.bt_request2, R.id.bt_request3})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_request1:
//                String url = "http://zuowen.api.juhe.cn/zuowen/typeList";
//                String key = "3624c4a3473a4348815e5e4702e2df4a";
                String url = "http://cbs-test.shenmajr.com/cbsapi/api/bclogin";

                Request<JSONObject> request = NoHttp.createJsonObjectRequest(url, RequestMethod.GET);
//                request.add("key",key);
//                request.add("type",2);
                request.add("DeviceModel","GN9010");
                request.add("AppVersion",41);
                request.add("password","63EBB148B7D450ACFFF069679FB4B0A3");
                request.add("loginId","15000983434");
                request.add("eqid","1507bfd3f7c7f2d313a");
                request.add("SystemName","GiONEE");
                request.add("SystemVersion","5.1");
                request.add("deviceid","869735021514048");
                request.add("DeviceName","");
                request.add("AppName","什马金融商户版");
                RequestQueue requestQueue = NoHttp.newRequestQueue();
                requestQueue.add(0, request, new OnResponseListener<JSONObject>() {
                    @Override
                    public void onStart(int what) {
                        System.out.println("start" );
                        time = System.currentTimeMillis();
                    }

                    @Override
                    public void onSucceed(int what, Response<JSONObject> response) {
                        System.out.println(response.get().toString());
                    }

                    @Override
                    public void onFailed(int what, String url, Object tag, Exception exception, int responseCode, long networkMillis) {
                        System.out.println(responseCode+"--e--"+exception.getMessage());
                    }

                    @Override
                    public void onFinish(int what) {
                        System.out.println("end");
                        System.out.println("time----"+(System.currentTimeMillis()-time)+"ms");
                    }
                });
                break;
            case R.id.bt_request2:
                break;
            case R.id.bt_request3:
                break;
        }
    }
}
